using System;
using System.Collections.Generic;
using System.Windows.Forms;
using GGEditor.API;
using GGEditor.API.Plugins;

namespace GGEditor.Core.UI
{
	[XmlNodeObjectFactory(Name = "DynamicMenuItem")]
	public class DynamicMenuItemFactory : MenuItemFactory
	{
		#region Implementation of IXmlNodeObjectFactory

		public override object Build(IPluginNode pluginNode, IDictionary<string, string> attributes)
		{
			ToolStripMenuItem menuItem = base.Build(pluginNode, attributes) as ToolStripMenuItem;
			if (menuItem == null)
				throw new InvalidOperationException();

			ToolStripMenuItem parentMenuItem = pluginNode.Parent.Object as ToolStripMenuItem;
			if (parentMenuItem == null)
			{
				// Top-level menu
				menuItem.DropDownOpening += delegate(object sender, EventArgs e)
				{
					// TODO get the populator
				};
			}
			else
			{
				// Sub-menu
				parentMenuItem.DropDownOpening += delegate(object sender, EventArgs e)
				{
					// TODO get the populator
				};
			}
			

			return menuItem;
		}

		#endregion
	}
}